home *** CD-ROM | disk | FTP | other *** search
- Path: castle.nando.net!news
- From: actuary@nando.net (Bill McCarthy)
- Newsgroups: comp.lang.c
- Subject: Re: Converting Strings to Upper Case
- Date: 17 Mar 1996 21:54:57 GMT
- Organization: Nando.net Public Access
- Message-ID: <4ii1nh$bng@castle.nando.net>
- References: <4ifra6$52i@scipio.cyberstore.ca> <DoFA24.AL7@iquest.net>
- Reply-To: actuary@nando.net (Bill McCarthy)
- NNTP-Posting-Host: grail814.nando.net
- X-Newsreader: IBM NewsReader/2 v1.2
-
- In <DoFA24.AL7@iquest.net>, dlmiller@iquest.net (Doug & Rose Miller) writes:
- >ejw@news.cyberstore.ca () wrote:
- >+Hi,
- >+
- >+I need to write a function to convert a string containg upper or lower case
- >+characters to the opposite case. Something like:
- >+
- >+ void libConvertUpperCase(char *str); and
- >+ void libConvertLowerCase(char *str);
- >+
- >+and the string would be modified. I just can't seem to wrap my head around
- >+the best way that I know is better than writing a for loop to check each
- >+element in the array?
- >+
- >+I apologize if this in the FAQ; I am still going thorugh it. Any help
- >+would be greatly appreciated.
- >+
- >+Eric Woodward.
- >+ejw@cyberstore.ca.
- >+
- >
- >
- >#include <stdio.h>
- >
- >void main (void) {
-
- Oh, please! Read the FAQ to avoid posting crap like this.
-
- >char test[] = "aBcDeFgHiJkLmNoPqRsTuVwXyZ";
- >char *p;
- >
- >printf ("%s\n", &test);
-
- &test ??? How about just test?
-
- >for (p = test; *p; *p++)
-
- And what do you think you are accomplishing with *p++ that p++ or ++p
- wouldn't do???
-
- > if (isalpha(*p)) *p ^= 0x20; /* for ascii machines e.g. PC; use 0x40 for ebcdic machines e.g. IBM mainframe */
-
- isalpha() has not been declared. It takes an int and *p may be a signed
- char, how about *(unsigned char *)p. Also, your code is toggling between
- upper and lower case.
-
- >printf ("%s\n", &test);
-
- There you go again with this &test thingy. Finally, you'll want a
- "return 0;" after you've fixed the "void main" error.
-
- >}
-
- Bill McCarthy
- actuary@nando.net
- Wendell, NC USA
-
-